home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UPrintHandler.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  10.6 KB  |  308 lines  |  [TEXT/MPS ]

  1. // UPrintHandler.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. //
  5. // This unit provides stub-outs for printing with MacApp.
  6. //
  7. //
  8. //
  9.  
  10. #ifndef __UPRINTHANDLER__
  11. #define __UPRINTHANDLER__
  12.  
  13. // MacApp
  14.  
  15. #ifndef __UBEHAVIOR__
  16. #include "UBehavior.h"
  17. #endif
  18.  
  19. #ifndef __UGEOMETRY__
  20. #include "UGeometry.h"
  21. #endif
  22.  
  23. //----------------------------------------------------------------------------------------
  24. // Forward and external class declarations. 
  25. //----------------------------------------------------------------------------------------
  26.  
  27. class TView;
  28. class TFile;
  29. class TDocument;
  30. class TPrintHandler;
  31. class TPrintInfo;
  32.  
  33. //----------------------------------------------------------------------------------------
  34. // Constants
  35. //----------------------------------------------------------------------------------------
  36.  
  37. const IDType kPrintBehaviorID = 'prnt';            // behavior id for print handler
  38. const IDType kPrintMenuBehaviorID = 'prmn';        // behavior id for print menu behavior
  39.  
  40. //----------------------------------------------------------------------------------------
  41. // TPrintMenuBehavior
  42. //----------------------------------------------------------------------------------------
  43.  
  44. class TPrintMenuBehavior : public TBehavior
  45. {
  46.     MA_DECLARE_CLASS;
  47.     
  48. public:
  49.  
  50.     TPrintHandler* fPrintHandler;                // the managed print handler
  51.  
  52.     TPrintMenuBehavior();
  53.         // Constructor
  54.     virtual ~TPrintMenuBehavior();
  55.         // Destructor
  56.         
  57.     void IPrintMenuBehavior(TPrintHandler*    itsPrintHandler);
  58.         // initializes this behavior, and sets fPrintHandler to itsPrintHandler
  59.  
  60.     //------------------------------------------------------------------------------------
  61.     // Menu Commands
  62.     //------------------------------------------------------------------------------------
  63.     
  64.     virtual Boolean DoScriptCommand(CommandNumber aCommandNumber,
  65.                                     TAppleEvent* messageEvent,
  66.                                     TAppleEvent* replyEvent);    // override
  67.         // forwards into fPrintHandlers DoScriptCommand
  68.         
  69.     //------------------------------------------------------------------------------------
  70.     // Menu Commands
  71.     //------------------------------------------------------------------------------------
  72.  
  73.     virtual void DoMenuCommand(CommandNumber aCommandNumber);
  74.         // forwards into fPrintHandler's DoPrintCommand
  75.  
  76.     virtual void DoSetupMenus();
  77.         // forwards into fPrintHandler's DoSetupPrintMenus
  78. };
  79.  
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // TPrintHandler: Handles printing at a specified resolution on behalf of a view. This
  83. // class is really a non-functional stub for programs that don't use the printing building
  84. // block.
  85. //----------------------------------------------------------------------------------------
  86.  
  87. class TPrintHandler : public TBehavior
  88. {
  89.     MA_DECLARE_CLASS;
  90.     
  91. public:
  92.     //----------------------------------------------------------------------------------------
  93.     // Initialization and termination
  94.     //----------------------------------------------------------------------------------------
  95.  
  96.     TPrintHandler();
  97.         // Constructor
  98.     virtual ~TPrintHandler();
  99.         // Destructor
  100.         
  101.     void IPrintHandler(TView* itsView);
  102.         // Initialize the printHandler, and associate it and 'itsView' with each other
  103.  
  104.     virtual Boolean Focus();
  105.         // Stub
  106.  
  107.     virtual void FocusOnInterior();
  108.         // Stub
  109.         
  110.     virtual CPoint GetQDOrigin();
  111.         // Stub
  112.  
  113.     virtual VPoint GetViewToQDOffset();
  114.         // Stub
  115.  
  116.     virtual TPrintInfo* GetPrintInfo();
  117.         // Stub. Returns NULL by default
  118.  
  119.     virtual void SetDefaultPrintInfo();
  120.         // Stub
  121.         
  122.     virtual TPrintMenuBehavior* GetManager();
  123.         // Return the managing behavior of this print handler
  124.         
  125.     virtual void SetManager(TPrintMenuBehavior* itsManager);
  126.         // Set fManager to the indicated manager
  127.  
  128.     virtual void SetOwner(TEventHandler* itsOwner); // override
  129.         // Register and unregister with the window when we are added
  130.         // to and removed from the view. 
  131.  
  132.  
  133.     //------------------------------------------------------------------------------------
  134.     // Printing-related reformatting and computations
  135.     //------------------------------------------------------------------------------------
  136.  
  137.     virtual void Invalidate();
  138.         // Mark as invalid and issue a changed message
  139.  
  140.     virtual void Update();
  141.         // Check if the target printer has changed and inform dependents if necessary
  142.  
  143.     virtual VPoint GetViewPerPage();
  144.         // Accessor, returns amount of the view visible on a page
  145.  
  146.     virtual CPoint GetDeviceRes();
  147.         // Accessor, returns formal printer resolution, spots per inch
  148.  
  149.     virtual VCoordinate BreakFollowing(VHSelect vhs,
  150.                                               VCoordinate previousBreak,
  151.                                               Boolean& automatic);
  152.         // Returns the location of the page break which follows the page break located at
  153.         // 'previousBreak', in direction vhs; returns automatic = true if the page-break is
  154.         // thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note
  155.         // that page-breaks in dimension 'v' are drawn as vertical lines, those in
  156.         // dimension 'h' as horizontal lines
  157.  
  158.     virtual VPoint CalcPageStrips();
  159.         // Recalculate the number of strips of pages in each dimension
  160.  
  161.     virtual VPoint CalcViewPerPage();
  162.         // Computes the amount of view, in each dimension, to be allocated to a printed
  163.         // page
  164.  
  165.     virtual VPoint LocatePageInterior(long pageNumber);
  166.         // Decide where the top-left-most point of the the interior of the page should be
  167.  
  168.     virtual void PrinterChanged();
  169.         // The metrics relating to printer use have changed; absorb the information and
  170.         // react
  171.  
  172.     virtual void RedoPageBreaks();
  173.         // Recompute the dividing lines between areas of the view which will be mapped
  174.         // into different printed pages
  175.  
  176.     virtual void Reset();
  177.         // Resets the print handler to the default values
  178.  
  179.  
  180.     //------------------------------------------------------------------------------------
  181.     // Printing-related menu mgmt
  182.     //------------------------------------------------------------------------------------
  183.  
  184.     virtual Boolean DoPrintCommand(CommandNumber aCommandNumber);
  185.         // handles posting the print command, returns true if handled
  186.  
  187.     virtual void DoSetupPrintMenus();
  188.         // sets up the print menus
  189.  
  190.  
  191.     //------------------------------------------------------------------------------------
  192.     // Printing-related commands
  193.     //------------------------------------------------------------------------------------
  194.  
  195.     virtual Boolean Print(CommandNumber itsCommandNumber);
  196.         // Returns TRUE to proceed.
  197.  
  198.     virtual Boolean SetupForFinder(CommandNumber aCommandNumber);
  199.         // Intended to set up the print handler for finder printing.
  200.  
  201.  
  202.     //------------------------------------------------------------------------------------
  203.     // Printing-related screen feedback
  204.     //------------------------------------------------------------------------------------
  205.  
  206.     virtual void DrawPrintFeedback(const VRect& area);
  207.         // Draw page-breaks, page-numbers, view-borders, rulers, etc.
  208.  
  209.     virtual void DrawPageBreak(VHSelect vhs,
  210.                                       long whichBreak,
  211.                                       VCoordinate loc,
  212.                                       Boolean automatic);
  213.         // Does nothing.
  214.  
  215.  
  216.     //------------------------------------------------------------------------------------
  217.     // Actual printing
  218.     //------------------------------------------------------------------------------------
  219.  
  220.     virtual long MaxPageNumber();
  221.         // Returns the largest page number which could be reasonably printed, given the
  222.         // properties of the view; in cases like a SpreadSheet, this is not necessarily as
  223.         // large as the product (row strips) x (column strips)
  224.  
  225.     virtual void SetPageInterior(long pageNumber);
  226.         // Set up the pad-space Interior rectangle for the given page number
  227.  
  228.     virtual void SetPageOffset(const VPoint& coord);
  229.         // Given the view coordinates of the top-left-most CPoint of the view which is
  230.         // being mapped into the current page (in coord), this method's job is to compute
  231.         // the correct fRelOrigin field for the current page
  232.  
  233.     //----------------------------------------------------------------------------------------
  234.     // member functions that are really stubs
  235.     //----------------------------------------------------------------------------------------
  236.  
  237.     virtual void TerminateUPrinting();
  238.     // Call to terminate the printing system
  239.  
  240.     virtual void PrepareForFinderPrinting(const FSSpec* targetPrinter);
  241.     // call this to prepare for printing from the finder
  242.     // if targetPrinter is non-NULL then it specifies a "drag print" target
  243.  
  244.     virtual void DispatcherIsAvailable();
  245.     // MacApp calls this when the dispatcher has been created and initialized.
  246.  
  247.     virtual long GetSavePrintInfoSize(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
  248.         // returns the number of bytes necessary to save the print info.
  249.  
  250.     virtual void SavePrintInfo(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
  251.         // Saves the print info to the passed in file.
  252.  
  253.     virtual TPrintInfo* RestorePrintInfo(TFile* itsFile, Boolean useRsrcFork = TRUE);
  254.         // Initializes the print info from the passed in file.
  255.  
  256.  
  257. public:
  258.     TView* fView;                                // The view whose printing is handled
  259.  
  260.     TDocument* fDocument;                        // the document printed by this handler
  261.     
  262.     TPrintMenuBehavior* fManager;                // All printhandlers are managed by a
  263.                                                 // seperate behavior which is installed
  264.                                                 // as a behavior of the document.  When
  265.                                                 // we are detached from the document it
  266.                                                 // needs to know who our manager is so
  267.                                                 // it can remove it from its list of
  268.                                                 // behaviors.
  269.  
  270.     long fFocusedPage;                            // page number that is currently focused
  271.  
  272.     Boolean fShowBreaks;                        // True if page breaks should be
  273.                                                 // displayed at the moment
  274.  
  275. protected:
  276.     VPoint fViewPerPage;                        // amount of the view visible on a page
  277.  
  278.     CPoint fDeviceRes;                            // formal printer resolution, spots per
  279.                                                 // inch
  280.  
  281.     //----------------------------------------------------------------------------------------
  282.     // static data members
  283.     //----------------------------------------------------------------------------------------
  284. public:
  285.     static Boolean gFinderPrintingProceed;            // proceed with Finder printing
  286.  
  287.     static Boolean gCouldPrint;
  288.         // whether Printer code is accessible to the application
  289.         
  290.     static VPoint gPageOffset;
  291.         // offset in view of page being printed
  292.  
  293.     static TPrintHandler* gNullPrintHandler;        
  294.         // handles printing-relating messages for views which don't print
  295.     
  296.     static TPrintHandler* gPrintHandler;
  297.         // a global print-handler object for use in some standard printing-related activities;
  298.         // this is initialized to be just a reference to gNullPrintHandler, but if you call
  299.         // InitUPrinting, that will install a non-trivial print-handler here
  300.     
  301.     static TPrintHandler* gCurrPrintHandler;        
  302.         // If printing, this is set to the print handler. NULL if not printing.
  303. };
  304.  
  305.  
  306.  
  307. #endif // __UPRINTHANDLER__
  308.